package com.wbdgj.ui.home;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.RequiresApi;
import android.support.v4.app.ActivityCompat;
import android.util.Log;
import android.view.View;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.zxing.WriterException;
import com.igexin.sdk.PushManager;
import com.wbdgj.R;
import com.wbdgj.base.BaseActivity;
import com.wbdgj.base.BaseApplication;
import com.wbdgj.http.HttpAdapter;
import com.wbdgj.http.OnResponseListener;
import com.wbdgj.model.ResultUrlModel;
import com.wbdgj.ui.login.LoginActivity;
import com.wbdgj.ui.uitool.ShareBoard;
import com.wbdgj.ui.uitool.ShareBoardlistener;
import com.wbdgj.ui.uitool.SnsPlatform;
import com.wbdgj.utils.QRCodeUtil;
import com.wbdgj.utils.SpKeyUtils;
import com.wbdgj.utils.ToastUtils;
import com.wbdgj.views.RichTextView;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

import butterknife.BindView;
import cn.jiguang.share.android.api.JShareInterface;
import cn.jiguang.share.android.api.PlatActionListener;
import cn.jiguang.share.android.api.Platform;
import cn.jiguang.share.android.api.ShareParams;
import cn.jiguang.share.facebook.Facebook;
import cn.jiguang.share.facebook.messenger.FbMessenger;
import cn.jiguang.share.qqmodel.QQ;
import cn.jiguang.share.qqmodel.QZone;
import cn.jiguang.share.twitter.Twitter;
import cn.jiguang.share.wechat.Wechat;
import cn.jiguang.share.wechat.WechatFavorite;
import cn.jiguang.share.wechat.WechatMoments;
import cn.jiguang.share.weibo.SinaWeibo;
import cn.jiguang.share.weibo.SinaWeiboMessage;
import retrofit2.Call;

public class YhqDetailMyGaginActivity extends BaseActivity{

    private Context context = this;

    private  String ABLE_BRANCH_NAME, BRANCH_NAME, USE_BEG, USE_END, DESCRIBES;
    @BindView(R.id.yxq)
    TextView yxq;
    @BindView(R.id.symd)
    TextView symd;
    @BindView(R.id.sysm)
    RichTextView sysm;
    @Override
    protected int getLayoutResId() {
        return R.layout.ui_wb_yhq_my_detail_again;
    }

    @Override
    protected void initView() {
        ABLE_BRANCH_NAME = getIntent().getStringExtra("ABLE_BRANCH_NAME");
        BRANCH_NAME = getIntent().getStringExtra("BRANCH_NAME");
        USE_BEG = getIntent().getStringExtra("USE_BEG");
        USE_END = getIntent().getStringExtra("USE_END");
        DESCRIBES = getIntent().getStringExtra("DESCRIBES");
        if (DESCRIBES.equals("")){
            sysm.setVisibility(View.GONE);
        }else{
            sysm.setVisibility(View.VISIBLE);
        }
        sysm.setRichText(DESCRIBES);
//        sysm.loadDataWithBaseURL(null, DESCRIBES, "text/html", "utf-8", null);
//        WebSettings webSettings = sysm.getSettings();
//        webSettings.setJavaScriptEnabled(true);
//        sysm.setWebViewClient(new WebViewClient() {
//            @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
//            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
//                Intent intent = new Intent();
//                intent.setAction("android.intent.action.VIEW");
//                Uri content_url = Uri.parse(request.getUrl().toString());
//                intent.setData(content_url);
//                startActivity(intent);
//                return true;
//            }
//            @Override
//            public void onPageFinished(WebView view, String url) {
//                super.onPageFinished(view, url);
//            }
//        });

        if (ABLE_BRANCH_NAME.equals("null")){
            symd.setText(BRANCH_NAME);
        }else{
            symd.setText(ABLE_BRANCH_NAME);
        }

        yxq.setText(formatDate1(USE_BEG)+" 至 "+ formatDate1(USE_END));
    }

    public static String formatDate1(String dateStr) {
        DateFormat formatFrom = new SimpleDateFormat("MMM dd,yyyy", Locale.ENGLISH);
        Date date = null;
        try {
            date = formatFrom.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        DateFormat formatTo = new SimpleDateFormat("yyyy/MM/dd");
        return formatTo.format(date)+"";
    }
}
